import Vue from 'vue'
import VueRouter from 'vue-router'
const login = () => import(/* webpackChunkName:"login_home_welcome" */ '../views/login.vue')
// import login from '../views/login.vue'
const home = () => import(/* webpackChunkName:"login_home_welcome" */ '../views/home')
// import home from "../views/home";
const numbering = () => import(/* webpackChunkName:"numbering" */ '../views/numbering/numbering')
// import numbering from "../views/numbering/numbering";
const myself = () => import(/* webpackChunkName:"myself" */ '../views/myself/myself')
// import myself from "../views/myself/myself";
const contentexamine = () => import(/* webpackChunkName:"examine" */ '../views/examine/contentexamine')
// import contentexamine from "../views/examine/contentexamine";
const comment = () => import(/* webpackChunkName:"examine" */ '../views/examine/comment')
// import comment from "../views/examine/comment";
const useruser = () => import(/* webpackChunkName:"user" */ '../views/user/useruser')
// import useruser from "../views/user/useruser";
const useradmin = () => import(/* webpackChunkName:"user" */ '../views/user/useradmin')
// import useradmin from "../views/user/useradmin";
const managementlable = () => import(/* webpackChunkName:"management" */ '../views/management/managementlable')
// import managementlable from "../views/management/managementlable";
const carousel = () => import(/* webpackChunkName:"management" */ '../views/management/carousel')
// import carousel from "../views/management/carousel";
const jubao = () => import(/* webpackChunkName:"kefu" */ '../views/kefu/jubao')
// import jubao from "../views/kefu/jubao";
const fankui = () => import(/* webpackChunkName:"kefu" */ '../views/kefu/fankui')
// import fankui from "../views/kefu/fankui";
const shensu = () => import(/* webpackChunkName:"kefu" */ '../views/kefu/shensu')
// import shensu from "../views/kefu/shensu";

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  { path: '/login', name: 'login', component: login, meta: { ispublic: true } },
  {
    path: '/',
    name: 'home',
    component: home,
    children: [
      { path: '', name: 'numbering', component: numbering },
      { path: 'myself', name: 'myself', component: myself },
      { path: 'contentexamine', name: 'contentexamine', component: contentexamine },
      { path: 'comment', name: 'comment', component: comment },
      { path: 'useruser', name: 'useruser', component: useruser },
      { path: 'useradmin', name: 'useradmin', component: useradmin },
      { path: 'managementlable', name: 'managementlable', component: managementlable },
      { path: 'carousel', name: 'carousel', component: carousel },
      { path: 'jubao', name: 'jubao', component: jubao },
      { path: 'fankui', name: 'fankui', component: fankui },
      { path: 'shensu', name: 'shensu', component: shensu }
    ]
  }
  /* {路由懒加载
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/!* webpackChunkName: "about" *!/ '../views/About.vue')
  } */
]

const router = new VueRouter({
  routes
})
// 挂载路由导航守卫
router.beforeEach((to, Form, next) => {
  if (!to.meta.ispublic && (!localStorage.admin_jwt_token || !localStorage.uinfo)) {
    return next('/login')
  } else if (to.meta.ispublic && localStorage.uinfo && localStorage.admin_jwt_token) {
    return next(Form.path)
  }
  next()
})

export default router
